#coding=utf-8

from .model import Asset, AssetType, AssetAttr, TypeAttr

# register organ
def add_assets(login_name, password):
    org_obj = Orgnization.all_objects().filter(login_name = login_name).select()

    if org_obj:
        return False, 'registered.'
    # gen password
    sec_password = AuthPassword(password)

    org_model = Orgnization()
    org_model.login_name = login_name
    org_model.password = sec_password.password

    org_model.save()

    return True, 'success.'

# organ login
def org_login(login_name, password):
    org_obj = Orgnization.all_objects().filter(login_name = login_name).select()

    if not org_obj:
        return False, 'user name not exists.'

    sec_password = AuthPassword(password)
    ret = sec_password.verify(org_obj.password)

    if not ret:
        return False, 'user password is not right.'

    return True, ''


